﻿using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace MyVocabulary
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {            
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if(!Uninstall())
                Application.Run(new Main());
        }

        public static bool Uninstall()
        {
            try
            {
                var args = Environment.GetCommandLineArgs();
                foreach (var arg in args)
                {
                    var values = arg.Split("=".ToCharArray());
                    if (values.Length > 1 && values[0] == "/u")
                    {
                        var guid = values[1];
                        var path = Environment.GetFolderPath(Environment.SpecialFolder.System);
                        var si = new ProcessStartInfo(string.Format("{0}\\msiexec.exe", path),
                                                      string.Format("/x {0}", guid));
                        Process.Start(si);
                        Application.Exit();
                        return true;
                    }
                }
            }
            catch
            {
                //Run application normally if it fails to uninstall
            }

            return false;
        }
    }
}
